/*
 * Author Anju
 */
package com.sdi.columbus;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

public class GetLatLong {

//	int custid;
	String userID;
	GpsData gpsg=new GpsData();
	 
//    public String GetValue(int id) throws JSONException, IOException
	public String GetValue(String accountID, String id) throws JSONException, IOException
    {
    	
           String result="";
           
    	   
    	// Add your data
    	
    	   JSONObject user =  new JSONObject();
    	 
    	
//    	   user.put("ClientID",String.valueOf(gpsg.getCustomerId()));
    	   user.put("accountID", accountID);
    	   user.put("vehicleID", String.valueOf(id));
    	// Create a new HttpClient and Post Header
    	
    	   HttpClient client = new DefaultHttpClient();
    	   URI website;
		   try {
			        website = new URI("http://deepam.cloudapp.net/ColumbusRESTService/ColumbusREST.svc/json/GetLatestGPSForVehicle");
			        HttpPost request = new HttpPost();
	    	        request.setEntity(new StringEntity(user.toString()));
	    	        request.addHeader("content-type", "application/json");      
	    	        request.setURI(website);
	    	
	    // Execute HTTP Post Request
	    	        HttpResponse response = client.execute(request);
	    	        HttpEntity entity = response.getEntity();
			        result = EntityUtils.toString(entity);
	    	

	    	        System.out.println("location details from getlatlong"+result);
		         } 
		   catch (URISyntaxException e) 
		        {
			          // TODO Auto-generated catch block
			          e.printStackTrace();
		         }
    	
    	
		      return result; 	
    	
    }    
	
}
